import initServerInstance from '../server/initServerInstance';

export const version = '1.5.0';

if (require.main === module) {
	(async () => {
		const server = await initServerInstance({
			loggerConfig: {
				name: 'upgrade',
				alwaysCreate: true,
			},
		});

		for await (const record of server.app.model.Task.find({
			taskType: 'ssl',
			status: 'completed',
		})) {
			const doc = record.toObject();

			record.result.warnings = doc.result.warnings.map(w => ({
				...w,
				affects: record.target,
			}));

			await record
				.save({ validateBeforeSave: false })
				.catch(error => console.log(error, record));
		}

		process.exit();
	})();
}
